package com.servlet.yanglaoyuan.service.impl;

import com.servlet.yanglaoyuan.mapper.Health_Checkup_DataMapper;
import com.servlet.yanglaoyuan.pojo.Health_Checkup_Data;
import com.servlet.yanglaoyuan.service.Health_Checkup_DataService;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@RequiredArgsConstructor
public class Health_Checkup_DataServiceImpl implements Health_Checkup_DataService {

    @Autowired
    private final Health_Checkup_DataMapper health_checkup_dataMapper;
    @Results({
            @Result(property = "date", column = "date", javaType = LocalDateTime.class)
    })
    //添加一条体检记录
    @Override
    public void add(Health_Checkup_Data health_checkup_data) {
        health_checkup_dataMapper.add(health_checkup_data);
    }

    //更新一条体检记录
    @Override
    public void updateCheckupData(Health_Checkup_Data health_checkup_data) {
        health_checkup_dataMapper.updateCheckupData(health_checkup_data);
    }

    //通过id查询一条体检记录
    @Override
    public Health_Checkup_Data getById(Integer id) {
        return health_checkup_dataMapper.getById(id);
    }

    //通过id删除一条体检记录
    @Override
    public void deleteCheckupData(Integer id) {
        health_checkup_dataMapper.deleteCheckupData(id);
    }

    //通过老人id查询其所有体检记录
    @Override
    public List<Health_Checkup_Data> getByElderlyId(Integer elderly_id) {
        return health_checkup_dataMapper.getByElderlyId(elderly_id);
    }

    //查询所有体检记录
    @Override
    public List<Health_Checkup_Data> getAll() {
        return (List<Health_Checkup_Data>) health_checkup_dataMapper.getAll();
    }

    //通过时间查询
    @Override
    public List<Health_Checkup_Data> getByDate(LocalDateTime startDate, LocalDateTime endDate) {
        return health_checkup_dataMapper.getByDate(startDate,endDate);
    }
}
